package bj.com.arms.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;

import bj.com.arms.R;
import bj.com.arms.di.component.DaggerNewsComponent;
import bj.com.arms.di.module.NewsModule;
import bj.com.arms.mvp.adapter.NewsPagerAdapter;
import bj.com.arms.mvp.contract.NewsContract;
import bj.com.arms.mvp.presenter.NewsPresenter;
import bj.com.arms.mvp.ui.fragment.NewsFragment;
import butterknife.BindView;
import butterknife.ButterKnife;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class NewsActivity extends BaseActivity<NewsPresenter> implements NewsContract.View, OnTabSelectListener {


    @BindView(R.id.top_tab)
    SlidingTabLayout topTab;
    @BindView(R.id.news_pager)
    ViewPager newsPager;

    private Context mContext = this;
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    private final String[] mTitles = {
            "头条", "社会", "国内",
            "国际", "娱乐", "体育", "军事",
            "科技", "财经", "时尚"
    };

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerNewsComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .newsModule(new NewsModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_news; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        for (String title : mTitles) {
            mFragments.add(NewsFragment.newInstance(title));
        }
        topTab.setOnTabSelectListener(this);

        newsPager.setAdapter(new NewsPagerAdapter(getSupportFragmentManager(),mFragments,mTitles));
        topTab.setViewPager(newsPager);

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void onTabSelect(int position) {

    }

    @Override
    public void onTabReselect(int position) {

    }
}
